﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MODEL;
using System.Data;
using System.Data.SqlClient;
using Newtonsoft.Json;

namespace DAL
{
  public   class KPurchaseDAL:IDAL.PurchaseIDAL
    {
        //创建数据库连接字符串
        SqlConnection conn = new SqlConnection("Data Source=169.254.82.63;Initial Catalog=Doruidotsystem;User ID=sa");
        /// <summary>
        /// 获取采购订单表数据
        /// </summary>
        /// <returns></returns>
        public List<PurchaseModel> K_GetPurchase()
        {
            conn.Open();
            string sql = "select * from PurchaseTable inner join Goodsinfo on PurchaseTable.PurchaseShopNameID =Goodsinfo.GoodsID inner join WareHouseInfo on  PurchaseTable.PurchaseShopNameID=WareHouseInfo.WareHouseID";
            SqlDataAdapter da = new SqlDataAdapter(sql,conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            var data = JsonConvert.SerializeObject(dt);
            var result = JsonConvert.DeserializeObject<List<PurchaseModel>>(data);
            conn.Close();
            return result;

        }

    }
}
